import type { TableColumnType } from 'ant-design-vue'
import type { IResponse } from '.'
import type { withIdx } from '@/utils'
import type { IMstPaper } from './dialog'

export type keys<T> = T extends Object ? keyof T | 'action' | 'fake' : never

export interface getAntTableColumn<T extends object> extends TableColumnType<T> {
  dataIndex: keys<T>
  visible?: boolean

  //只读宽度
  width: number

  //编辑态宽度
  widthForEdit?: number
}

export interface UserVO {
  id?: string
  createdTime: string
  isManager: number
  isSuperManager: number
  password: string
  realName: string
  userId: string
  updatedTime: string
  userName: string
  searchType: number
}


export interface AuditVO {
  id?: string
  name: string,
  phone: string,
  entName: string,
  position: string,
  description: string,
  auditStatus: string | number,
  createdTime: string,
}

export interface TeamManageVO {
  id?: string
  teamName?: string
  entName?: string
  phone?: string
  customerName: string
  peopleLimit: number
  lastedLoginTime: string
  expiredTime: string
  usedStatus: number
  authorityStatus: number
  formulaAuthority: number
}

export interface TeamMemberTableVO {
  id?: string
  customerName: string
  phone: string
  roleType: number
  createdTime: string
  lastedLoginTime: string
}

export type UserColumn = getAntTableColumn<UserVO>

export type AuditManageColumn = getAntTableColumn<AuditVO>
export type TeamManageColumn = getAntTableColumn<TeamManageVO>
export type TeamMemberTableColumn = getAntTableColumn<TeamMemberTableVO>

export interface IDialogData {
  lastQuetionTime: string
  dialogName: string
  id: string
  updatedTime: string
  userId: string,
  fileUrl?: string,
  queryType: number,
  pdfId?: string,
  processStatus?: number,
  fileSize?: string,
  fileName?: string,
  documentType?: number,
}

export interface IAnswer {
  answerContent: string
  answerId: string
  answerTimestamp: number
  createdTimestamp: number
  customerId: string
  duration: number
  externalUserId: number
  hasCleanLine: true
  hasDeleted: number
  hasShare: number
  hasSupport: number
  id: string
  questionContent: string
  questionId: string
  questionType: number
  questionUrl: string
  relatedArticles: Article[]
  suggestQuestionList: string[]
  //论文Id
  resourceIds: string[]
  responseState: string

  sessionId: string
  supportUpdateTime: string
  searchType: number
}

export interface IParam {
  pageNum: number
  pageSize: number
}

export interface UserListParam extends IParam {
  userName: string
  realName: string
}

export interface Article {
  authorName: string
  chatConversationArticleRelId: string
  content: string
  icon: string
  id: string
  isRelated: number
  splitId: string
}

// 1 正在思考
// 2 正在查找
// 3 检索到文档(正在总结)
// 4 未检索到文档(AI作答,正在总结)
// 6 正在回答
// 7 回答结束
// 8 响应超时
// 9 回答完成(包含引导问题)

export enum EAnswerState {
  //正在思考
  'THINKING' = 1,
  //正在查找
  'SEARCHING' = 2,
  //正在总结 检索到文档
  // 'PAPER_FOUND',
  //正在总结 未检索到文档
  // 'PAPER_NOT_FOUND',
  'ANSWERING' = 4,
  // 回答完成
  'FINISH_ANSWER' = 6,
  // 响应超时
  'OVERTIME',
  // 中断回答
  'INTERRUPT'
  // 'COMPLETE'
}

export enum ENodeType {
  //单节点
  SINGLE_NODE = 1,
  //多节点
  MULTI_NODE = 2
}


export enum EDocumentType {
  //专利
  'PATENT' = '1',
  //论文
  'DOCUMENT' = '2',
  //其他
  'OTHER' =  '3',
  //配方
  'RECIPE' = '4',
  // 网页
  'WEB' = '5'
}

export const DocumentTypeList = [
  {
    code: EDocumentType.PATENT,
    label: '专利'
  },
  {
    code: EDocumentType.DOCUMENT,
    label: '论文'
  },
  {
    code: EDocumentType.RECIPE,
    label: '配方'
  },
  {
    code: EDocumentType.OTHER,
    label: '其他'
  },
  {
    code: EDocumentType.WEB,
    label: '网页'
  }
]

export const DISPLAY_STATUS = [
  {
    code: EAnswerState.THINKING,
    label: '数字材料助理工程师正在思考~'
  },

  {
    code: EAnswerState.SEARCHING,
    label: '正在搜索'
  },

  {
    code: EAnswerState.PAPER_FOUND,
    label: '正在总结'
  },

  {
    code: EAnswerState.PAPER_NOT_FOUND,
    label: '正在总结'
  },

  {
    code: EAnswerState.ANSWERING,
    label: '正在回答'
  }
]

export interface MainItem {
  answerState: EAnswerState
  keyWordList?: string[]
  id: string
  fakeId: string
  contentType: string
  groupId: string
  message: string
  // plainText: string
  type: string
  date: string
  replyState: number | boolean
  answerContent: string
  answerId: string
  answerTimestamp: number
  createdTimestamp: number
  customerId: string
  duration: number
  externalUserId: number
  hasCleanLine: true
  hasDeleted: number
  hasShare: number
  hasSupport: number
  questionContent: string
  questionId: string
  questionType: number
  questionUrl: string
  relatedArticles: Article[]
  suggestQuestionList: string[]
  //论文Id
  resourceIds: string[]
  // 响应状态 1正常数据 2响应超时 3网络异常

  paperList?: IMstPaper[]

  responseState: string
  sessionId: string
  supportUpdateTime: string
  error: Boolean
  searchType: number
  pdfPageIdList: string[]
  queryType: number
  hint: string // 提示
  thinkingContent: string[] //思考内容
  searchingList: any[] //查找列表
  nodeType: number //节点类型 1单节点 2多节点
  text: string
  answerContentList: any
  currentNodeMessage: any
  isFlowing: boolean // 是否正在流式输出
  isHistory: boolean // 是否是历史数据
}

export interface MainItemVo extends Partial<MainItem> {
  isLoading?: boolean
  relatedArticles?: withIdx[]
  isLastOne?: boolean
  opened?: boolean
  hasCursor?: boolean
  isMultiNode?: boolean
  isAnswering?: boolean
  subIndex?: number
}

export interface IPage<T = any> {
  rows: Array<T>
  total: number
}

export interface IPageResp<T = any> extends IResponse<IPage<T>> {}

export interface LoginForm {
  phone: string
  password?: string
  code?: string
  type: number
}

export interface ApplyForm {
  phone: string
  code?: string
  description: string
  position: string
  entName: string
  name:string
}
export interface UpdatePassWordForm {
  phone: string,
  code: string,
  confirmPassword:string,
  password: string
}
export interface InviteLogin{
  code: string,
  phone: string,
}

export interface InviteInfo {
  customerId?:string,
  id:string,
  phone:string,
  teamId?:string,
  teamName:string
}
export interface JoinTeamType{
  customerId?: string,
  inviteInfoId: string
}

export interface UserInfo{
  name?: string,
  phone?: string,
  roleType: number,
  logoUrl?: string,
  currentTeamId: string,
  currentTeamName: string,
  authorityStatus: number,
  formulaAuthority: number,
  id: string,
  password?: string
}

export interface PdfFile{
  url:string,
  name:string,
  paperId?: string,
  pdfId?: string,
  size?: string,
  documentType?: number
}

export interface  GuideItem{
  id?:string,
  title?: string,
  description?: string,
  content?: string,
  seq?: number | '',
  iconUrl?: string,
  iconName?: string,
  status?: 0 | 1,
  isEdit?: boolean,
  type: 1 | 2 | 3, //1检索对话欢迎语 2文档解读欢迎语 3首页引导
  questionType?: number | ''
}
